 package server;

 import client.MapleCharacter;
 import com.alibaba.druid.pool.DruidPooledConnection;
 import database.DatabaseConnection;
 import handling.channel.ChannelServer;
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.text.SimpleDateFormat;
 import java.util.Calendar;
 import java.util.Date;
 import java.util.LinkedHashMap;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;



 public class MapleSignin
 {
   public static final int MINLEVEL = 33;
/*  23 */   private static final MapleSignin instance = new MapleSignin();
/*  24 */   private final List<SiginRewardInfo> siginrewards = new LinkedList<>();

   public static MapleSignin getInstance() {
/*  27 */     return instance;
   }






   public static String getCurrentTime() {
/*  36 */     return "check1=0;cDate=" + (new SimpleDateFormat("yy/MM/dd")).format(new Date());
   }

   public List<SiginRewardInfo> getSiginRewards() {
/*  40 */     return this.siginrewards;
   }

   public void load() {
/*  44 */     if (this.siginrewards.isEmpty()) {
/*  45 */       reload(false);
     }
   }






   public void reload(boolean isCommand) {
/*  55 */     this.siginrewards.clear();
/*  56 */     try (DruidPooledConnection con = DatabaseConnection.getInstance().getConnection()) {
/*  57 */       PreparedStatement ps = con.prepareStatement("SELECT * FROM data_signin_reward");
/*  58 */       ResultSet rs = ps.executeQuery();

/*  60 */       while (rs.next()) {





/*  66 */         SiginRewardInfo reward = new SiginRewardInfo(rs.getInt("id"), rs.getInt("itemid"), rs.getInt("quantity"), rs.getInt("expiredate"), rs.getInt("isCash"));

/*  68 */         this.siginrewards.add(reward);
       }
/*  70 */       ps.close();
/*  71 */       rs.close();
/*  72 */     } catch (SQLException e) {
/*  73 */       System.err.println("Error handling siginreward" + e);
     }

/*  76 */     Calendar cal = Calendar.getInstance();
/*  77 */     cal.setTimeInMillis(System.currentTimeMillis());
/*  78 */     int today = cal.get(5);


/*  81 */     if (!isCommand && today == 1) {
/*  82 */       try(DruidPooledConnection con = DatabaseConnection.getInstance().getConnection(); 
/*  83 */           PreparedStatement ps = con.prepareStatement("DELETE FROM questinfo WHERE quest = ?")) {
/*  84 */         ps.setInt(1, 7);
/*  85 */         ps.executeUpdate();
       }
/*  87 */       catch (SQLException e) {
/*  88 */         System.err.println("清除签到记录失败.");
       }

/*  91 */       for (ChannelServer channelServer : ChannelServer.getAllInstances()) {
/*  92 */         for (MapleCharacter player : channelServer.getPlayerStorage().getAllCharacters()) {
/*  93 */           if (player != null) {
/*  94 */             player.removeInfoQuest(7);
           }
         }
       }
     }
   }






   public Map<Integer, Integer> getUnknownMap() {
/* 107 */     Map<Integer, Integer> ret = new LinkedHashMap<>();
/* 108 */     ret.put(Integer.valueOf(100), Integer.valueOf(40914));
/* 109 */     ret.put(Integer.valueOf(101), Integer.valueOf(40914));
/* 110 */     return ret;
   }

   public class SiginRewardInfo {
     private final int rank;
     private final int itemid;
     private final int quantity;
     private final int expiredate;
     private final int isCash;

     SiginRewardInfo(int rank, int itemid, int quantity, int expiredate, int isCash) {
/* 121 */       this.rank = rank;
/* 122 */       this.itemid = itemid;
/* 123 */       this.quantity = quantity;
/* 124 */       this.expiredate = expiredate;
/* 125 */       this.isCash = isCash;
     }

     public int getRank() {
/* 129 */       return this.rank;
     }

     public int getItemId() {
/* 133 */       return this.itemid;
     }

     public int getQuantity() {
/* 137 */       return this.quantity;
     }

     public int getExpiredate() {
/* 141 */       return this.expiredate;
     }

     public int getIsCash() {
/* 145 */       return this.isCash;
     }
   }
 }


/* Location:              C:\PGX\Server.jar!\server\MapleSignin.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */